package com.come4loves.game.dataconfig.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.come4loves.core.dataconfig.ServiceAdapter;
import com.come4loves.core.utils.Splitable;
import com.come4loves.game.dataconfig.model.SpellCardConfig;

/**
 * 技能卡
 * 
 * @author jerry
 *
 */
@Component
public class SpellCardService extends ServiceAdapter {

	private static Map<Integer, SpellCardConfig> configMap = new HashMap<Integer, SpellCardConfig>();

	@Override
	public void clear() {
		configMap.clear();
	}

	@Override
	public void initialize() {
		List<SpellCardConfig> list = this.dataConfig.listAll(this, SpellCardConfig.class);
		for (SpellCardConfig config : list) {
			configMap.put(config.getId(), config);
		}
	}

	public static SpellCardConfig get(int id) {
		return configMap.get(id);
	}

	public static boolean exsit(int goodsId) {
		return configMap.containsKey(goodsId);
	}
	
	public static String exportAllSpell() {
		StringBuffer sBuffer = new StringBuffer();
		for (SpellCardConfig cardConfig : configMap.values()) {
			sBuffer.append(cardConfig.toString()).append(Splitable.ELEMENT_DELIMITER);
		}
		return sBuffer.deleteCharAt(sBuffer.length() - 1).toString();
	}
}
